/**
* 基础菜单 api 管理
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>api 管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="requestData" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="requestData.apiName" placeholder="api名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="showAddDialog()">添加</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border
              element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column sortable prop="id" label="api id" width="300">
      </el-table-column>
      <el-table-column sortable prop="apiName" label="api名称" width="300">
      </el-table-column>
      <el-table-column sortable prop="apiPath" label="请求路径" width="300">
      </el-table-column>
      <el-table-column sortable prop="serviceName" label="服务名称" width="300">
      </el-table-column>
      <el-table-column sortable prop="methodName" label="方法名称" width="300">
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="300">
        <template slot-scope="scope">
          <el-button size="mini" @click="edit(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>


    <el-dialog :title="title" :visible.sync="editFormVisible" width="50%" @click='add()'>
      <el-form label-width="80px" ref="editForm" :model="addOrUpdateApiInfo" :rules="rules">
        <el-form-item label="api名称" prop="apiName">
          <el-input size="small" v-model="addOrUpdateApiInfo.apiName" auto-complete="off"
                    placeholder="api名称"></el-input>
        </el-form-item>
        <el-form-item label="请求路径" prop="apiPath">
          <el-input size="small" v-model="addOrUpdateApiInfo.apiPath" auto-complete="off" placeholder="请求路径"></el-input>
        </el-form-item>
        <el-form-item label="应用名称" prop="appName">
          <el-input size="small" v-model="addOrUpdateApiInfo.appName" auto-complete="off" placeholder="应用名称"></el-input>
        </el-form-item>
        <el-form-item label="描述信息" prop="apiDescription">
          <el-input size="small" v-model="addOrUpdateApiInfo.apiDescription" auto-complete="off"
                    placeholder="描述信息"></el-input>
        </el-form-item>
        <el-form-item label="dubbo 服务" prop="serviceName">
          <el-input size="small" v-model="addOrUpdateApiInfo.serviceName" placeholder="dubbo 服务"></el-input>
        </el-form-item>
        <el-form-item label="方法名称" prop="methodName">
          <el-input size="small" v-model="addOrUpdateApiInfo.methodName" placeholder="方法名称"></el-input>
        </el-form-item>
        <el-form-item label="版本" prop="methodName">
          <el-input size="small" v-model="addOrUpdateApiInfo.version" placeholder="版本号"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click='closeDialog()'>取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click="add()">保存
        </el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import Pagination from '../../components/Pagination'
import {apiAddOrUpdate, apiPageInfo, GetDubboPage} from "../../api/basisMG";

export default {
  data() {
    return {

      loading: false, //是显示加载
      editFormVisible: false,
      requestData: {
        apiName: null,
        pageQuery: {
          pageSize: 10,
          pageNum: 1
        }
      },
      title: '添加',
      addOrUpdateApiInfo: {
        id: null,
        apiName: '',
        apiPath: '',
        appName: '',
        apiDescription: '',
        serviceName: '',
        methodName: '',
        version: ''
      },
      listData: [], //用户数据
      rules: {
        apiName: [
          { required: true, message: 'api 名称', trigger: 'blur' }
        ],
        apiPath: [{ required: true, message: '请求路径', trigger: 'blur' }]
      },
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.requestData)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取公司列表
    getdata() {
      this.loading = true
      // 模拟数据开始

      let _this = this
      apiPageInfo(this.requestData).then(data => {
        _this.listData = data.body.dataList;
        _this.pageparm.total = data.body.total;
      })
      this.loading = false
    },
    // 分页插件事件
    callFather(parm) {
      this.requestData.pageQuery.pageNum = parm.currentPage
      this.requestData.pageQuery.pageSize = parm.pageSize
      this.getdata()
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    // 添加api 信息

    showAddDialog() {
      let _this = this;
      _this.editFormVisible = true;
    },
    closeDialog() {
      let _this = this;
      _this.editFormVisible = false;
    },
    add() {
      apiAddOrUpdate(this.addOrUpdateApiInfo).then(resp => {
        let _this = this;
        this.$message({
          type: 'success',
          message: resp.message
        })
        _this.editFormVisible = false;
      });
    },
    edit(data) {
      let _this = this;
      _this.editFormVisible = true;
      //初始值
      this.addOrUpdateApiInfo = data;

    }
  }

}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}

.userRole {
  width: 100%;
}
</style>


